import { createApp } from "vue";
import Toast from "../components/toast/Toast.vue";

export default {
  install: (app, options) => {
    // Toast插件,option为配置选项
    const toast = (message, type = "info", duration = 3000) => {
      const mountNode = document.createElement("div");
      document.body.appendChild(mountNode);
      //挂载到div节点上进行显示
      const toastApp = createApp(Toast, { message, type, duration });
      toastApp.mount(mountNode);

      setTimeout(() => {
        toastApp.unmount();
        document.body.removeChild(mountNode);
      }, duration);
    };

    app.provide("toast", toast);
  },
};
